<template>
  <!-- 放置表单 -->
  <el-form ref="userForm" :model="userInfo" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
    <el-form-item label="姓名:" prop="username">
      <el-input v-model="userInfo.username" style="width:300px" type="text" />
    </el-form-item>
    <el-form-item label="密码:">
      <el-input v-model="userInfo.password" style="width:300px" type="password" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="hSaveUserDetailById">更新</el-button>
      <el-button @click="$router.back()">返回</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { getUserDetailById, saveUserDetailById } from '@/api/user'
export default {
  name: 'LoginSetting',
  data() {
    return {
      userId: this.$route.query.yyds,
      userInfo: {},
      rules: {
        username: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {
    this.hGetUserDetailById()
  },
  methods: {
    async hGetUserDetailById() {
      const res = await getUserDetailById(this.userId)
      this.userInfo = res
    },
    hSaveUserDetailById() {
      this.$refs.userForm.validate(async vali => {
        if (vali) {
          await saveUserDetailById(this.userInfo)
          this.$message.success('修改成功!')
        }
      })
    }
  }
}
</script>
